<!--
 * @Description:实时对账
-->
<template>
  <div v-loading="page.bodyLoading" element-loading-text="对账中" element-loading-spinner="el-icon-loading" class="registered-container totalRevenue appMainWarp">
    <el-form :inline="true" :model="searchKey" class="demo-form-inline">
      <el-form-item label="院区:">
        <el-select v-model="searchKey.hospital_area_no" placeholder="请选择">
          <el-option
            v-for="item in searchKey.Hospital"
            :key="item.area_code"
            :label="item.area_name"
            :value="item.area_code"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="选择支付场景:">
        <el-select v-model="searchKey.system_no" multiple placeholder="请选择支付场景" clearable>
          <el-option
            v-for="item in searchKey.System"
            :key="item.pay_scene_no"
            :label="item.pay_scene_name"
            :value="item.pay_scene_no"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="getSumCompare(1, searchKey.time)">查询</el-button>
        <el-button type="primary" icon="el-icon-search" @click="onLoad">刷新对账</el-button>
      </el-form-item>
    </el-form>

    <template>
      <el-table
        ref="table"
        v-loading="page.tableLoading"
        v-el-height-adaptive-table="{bottomOffset: 90}"
        max-height="500px"
        center
        class="table"
        :data="searchData"
        stripe
        border
      >
        <el-table-column label="时间" align="center" prop="time">
          <template slot-scope="scope">{{ scope.row.date||'0' }}</template>
        </el-table-column>
        <el-table-column
          :key="0"
          prop="system"
          label="支付场景"
          align="center"
        >
          <template slot-scope="scope">{{ scope.row.system||'0' }}</template>
        </el-table-column>
        <el-table-column
          :key="1"
          prop="self_total_fee"
          label="支付场景收入"
          align="center"
        >
          <template slot-scope="scope">{{ scope.row.self_total_fee||'0' }}</template>
        </el-table-column>
        <el-table-column
          :key="2"
          prop="his_total_fee"
          label="HIS系统收入"
          align="center"
        >
          <template slot-scope="scope">{{ scope.row.his_total_fee	||'0' }}</template>
        </el-table-column>
        <!-- <el-table-column
          :key="3"
          prop="bank_total_fee"
          label="支付系统收入"
          align="center"
        >
          <template slot-scope="scope">{{ scope.row.bank_total_fee	||'0' }}</template>
        </el-table-column> -->
        <el-table-column
          :key="4"
          label="支付场景—HIS系统"
          align="center"
          prop="self_his"
        >
          <template slot-scope="scope">
            <div
              :class="[scope.row.self_his > 0|| scope.row.self_his < 0? 'abnormal':'normal']"
              @click="jumpClick(scope.row,1,scope.row.self_his)"
            >{{ scope.row.self_his ||'0' }}</div>
          </template>
        </el-table-column>

        <!-- <el-table-column
          :key="5"
          label="支付场景—支付系统"
          align="center"
          prop="self_bank"
        >
          <template slot-scope="scope">
            <div
              :class="[scope.row.self_bank >0 || scope.row.self_bank <0?'abnormal':'normal']"
              @click="jumpClick(scope.row,2,scope.row.self_bank)"
            >{{ scope.row.self_bank ||'0' }}</div>
          </template>
        </el-table-column>

        <el-table-column
          :key="6"
          label="HIS系统—支付系统"
          align="center"
          prop="his_bank"
        >
          <template slot-scope="scope">
            <div
              :class="[scope.row.his_bank>0 || scope.row.his_bank<0?'abnormal':'normal']"
              @click="jumpClick(scope.row,3,scope.row.his_bank)"
            >{{ scope.row.his_bank||'0' }}</div>
          </template>
        </el-table-column> -->
      </el-table>
    </template>
    <pagination
      :total="page.totalRow"
      :page.sync="page.currentPage"
      :limit.sync="page.pageSize"
      @pagination="onSearch"
    />
  </div>
</template>

<script>
import elHeightAdaptiveTable from '@/directive/el-table'
import { getConfigType } from '@/api/transactRecords/index'
import { realtimecompare, sumCompare } from '@/api/generaLedger/index'
import Pagination from '@/components/Pagination' // 分页
export default {
  name: 'RealTimeRecord',
  components: {
    Pagination
  },
  directives: { elHeightAdaptiveTable },

  data() {
    return {
      compare_type: '', // 入参
      searchKey: {
        time: '', // 交易日期
        hospital_area_no: '', // 选择院区
        Hospital: [],
        system_no: '', // 平台
        System: [],
        reconciliation: '', // 对账业务
        reconciliationList: []
      },

      searchData: [],
      date_type: '', // 按什么显示
      page: {
        bodyLoading: false,
        tableLoading: false,
        currentPage: 1, // 当前页
        pageSize: 20, // 默认条数
        totalRow: 0, // 总条数
        totalPage: 0 // 总页数
      },
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now() - 8.64e7
        }
      },
      compare: '', // 对账业务
      system: '' // 平台
    }
  },

  created() {
    this.searchKey.time = this.utils.getDay(0, '-')
  },
  mounted() {
    this.getConfig()
  },
  methods: {
    // 系统配置搜索
    getConfig() {
      var that = this
      var params = {}
      getConfigType(params)
        .then(res => {
          that.searchKey.Hospital = res.data.hospital
          that.searchKey.System = res.data.scene
        })
        .catch(() => {})
    },
    // 查询列表
    onLoad() {
      this.page.currentPage = 1
      this.onSearch()
    },
    onSearch() {
      var params = {}
      var that = this
      params.type = '1'
      params.date = that.searchKey.time
      // var loading = this.$loading({
      //   lock: true,
      //   text: '对账中...',
      //   spinner: 'el-icon-loading'
      // })
      that.page.bodyLoading = true
      realtimecompare(params)
        .then((res) => {
          that.page.bodyLoading = false
          // loading.close()
          // this.$message({
          //   type: 'success',
          //   message: '拉取成功'
          // })
          // this.compare_type = res.data.compare_type
          // this.searchKey.time = res.data.date
          this.getSumCompare(res.data.compare_type, res.data.date)
        })
        .catch(() => {
          that.page.bodyLoading = false
          // loading.close()
          this.$message({
            type: 'error',
            message: '拉取失败'
          })
          that.searchData = []
        })
    },
    jumpClick(item, type, val) {
      // if (val === 0 || val === '0.00') {
      //   return
      // } else {
      this.$router.push({
        path: '/generaLedger/totalRevenue/totalRevenueDetail/index',
        query: {
          currentime: item.date,
          startime: this.searchKey.time[0],
          endtime: this.searchKey.time[1],
          comparetype: type
        }
      })
      // }
    },
    getSumCompare(busType, date) {
      var params = {}
      var that = this
      params.daytype = 'day'
      params.bustype = busType || 1
      params.startime = date
      params.endtime = date
      params.hospital = that.searchKey.hospital_area_no
      params.sceneno = that.searchKey.system_no.toString()
      that.page.tableLoading = true
      if (params.bustype !== '') {
        sumCompare(params)
          .then((res) => {
            that.page.tableLoading = false
            that.searchData = res.data.result
            that.page.totalPage = res.data.pages
            that.page.totalRow = parseInt(res.data.count)
          })
          .catch(() => {
            that.page.tableLoading = false
          })
      } else {
        that.searchData = []
        // this.$message({
        //   type: 'error',
        //   message: '请刷新对账'
        // })
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.totalRevenue {
  position: relative;
  width: 100%;
  .demo-form-inline {
    .el-button--primary {
      background-color: #579ef8 !important;
      color: #fff !important;
    }
    .el-button {
      background-color: #e8f4ff;
      color: #579ef8;
      border: 1px solid rgba(87, 158, 248, 1);
    }
  }
  .abnormal {
    color: red;
    text-decoration: underline;
    cursor: pointer;
  }
  .normal {
    color: rgb(113, 118, 133);
    cursor: pointer;
  }
}
</style>

